package org.hot100_6.leetcode230;

import org.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public int kthSmallest(TreeNode root, int k) {
        List<Integer> list = new ArrayList<>();

        tree2List(root,list);

        return list.get(k-1);
    }

    public void tree2List(TreeNode root, List<Integer> list){


        if (root==null){
            return ;
        }


        tree2List(root.left,list);

        list.add(root.val);

        tree2List(root.right,list);
    }
}
